package com.zhang.cloud.controller;

import com.zhang.cloud.entities.CommonResult;
import com.zhang.cloud.entities.Payment;
import com.zhang.cloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;

@RestController
@Slf4j
public class PaymentController {
    @Resource
    private PaymentService paymentService;

    @PostMapping(value = "/pay/add")
    public CommonResult add(@RequestBody Payment payment){
        int result = paymentService.add(payment);
        log.info("*****插入结果："+result);
        if(result > 0)
            return new CommonResult(200,"插入数据库成功",result);
        else
            return new CommonResult(444,"插入数据库失败",result);
    }

    @GetMapping(value = "/pay/get/{id}")
    public CommonResult<Payment>  select(@PathVariable("id") Long id){
        Payment payment = paymentService.getPaymentById(id);
        log.info("houhouhou"+payment);
        if(payment != null)
            return new CommonResult(200,"查询成功",payment);
        else
            return new CommonResult(444,"没有对应记录",null);

    }

    @GetMapping(value = "/pay/test")
    public CommonResult test()
    {
        String fuck= paymentService.get((long) 28);
        if(fuck!= null)
            return new CommonResult(200,"查询成功",fuck);
        else
            return new CommonResult(444,"没有对应记录",null);
    }

}
